# -*- coding: utf-8 -*-

import wx
import wx.xrc


###########################################################################
## Class Work 工作界面
###########################################################################
class Work(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"Onyx标版自动化测试工具v1.1", pos=wx.DefaultPosition,
                          size=wx.Size(475, 455), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHintsSz( wx.Size( 475, 455 ), wx.Size( 475,455 ) )

        gbSizer1 = wx.GridBagSizer(0, 0)
        gbSizer1.SetFlexibleDirection(wx.BOTH)
        gbSizer1.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        Step1 = wx.GridBagSizer(0, 0)
        Step1.SetFlexibleDirection(wx.BOTH)
        Step1.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText5 = wx.StaticText(self, wx.ID_ANY, u"第一步：点击获取设备按钮检查设备连接是否正常", wx.DefaultPosition,
                                           wx.DefaultSize, 0)
        self.m_staticText5.Wrap(-1)
        Step1.Add(self.m_staticText5, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_button3 = wx.Button(self, wx.ID_ANY, u"获取设备", wx.DefaultPosition, wx.DefaultSize, 0)
        Step1.Add(self.m_button3, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        gbSizer1.Add(Step1, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.EXPAND, 5)

        Step2 = wx.GridBagSizer(0, 0)
        Step2.SetFlexibleDirection(wx.BOTH)
        Step2.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText6 = wx.StaticText(self, wx.ID_ANY, u"第二步：点击连接等待设备与自动化程序建立连接\n         （成功连接后应用页会出现名为ATX的应用程序）",
                                           wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText6.Wrap(-1)
        Step2.Add(self.m_staticText6, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_button4 = wx.Button(self, wx.ID_ANY, u"建立连接", wx.DefaultPosition, wx.DefaultSize, 0)
        Step2.Add(self.m_button4, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        gbSizer1.Add(Step2, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.EXPAND, 5)

        Step3 = wx.GridBagSizer(0, 0)
        Step3.SetFlexibleDirection(wx.BOTH)
        Step3.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText2 = wx.StaticText(self, wx.ID_ANY, u"第三步：选择测试项目，然后点击执行：", wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText2.Wrap(-1)
        Step3.Add(self.m_staticText2, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        m_choice2Choices = [u"书城自动登录（如果已登录书城账号请先退出再执行）", u"书城自动点击", u"自动打开笔记增加笔画", u"Reader自动翻页（请先打开任意一本书再执行）", u"Reader自动翻页并增加笔画（请先打开任意一本书再执行）",u"APK安装"]
        self.m_choice2 = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice2Choices, 0)
        self.m_choice2.SetSelection(0)
        Step3.Add(self.m_choice2, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_button2 = wx.Button(self, wx.ID_ANY, u"执行", wx.DefaultPosition, wx.DefaultSize, 0)
        Step3.Add(self.m_button2, wx.GBPosition(1, 1), wx.GBSpan(1, 1), wx.ALL, 5)

        gbSizer1.Add(Step3, wx.GBPosition(2, 0), wx.GBSpan(1, 1), wx.EXPAND, 5)

        Settings = wx.GridBagSizer(0, 0)
        Settings.SetFlexibleDirection(wx.BOTH)
        Settings.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText8 = wx.StaticText(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText8.Wrap(-1)
        Settings.Add(self.m_staticText8, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_textCtrl3 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_textCtrl3.Hide()
        self.m_textCtrl3.SetMinSize(wx.Size(50, -1))

        Settings.Add(self.m_textCtrl3, wx.GBPosition(0, 2), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_staticText9 = wx.StaticText(self, wx.ID_ANY, u"执行次数：", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText9.Wrap(-1)
        self.m_staticText9.Hide()

        Settings.Add(self.m_staticText9, wx.GBPosition(0, 1), wx.GBSpan(1, 1), wx.ALL, 5)

        m_choice3Choices = [u"向后翻页", u"向前翻页"]
        self.m_choice3 = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice3Choices, 0)
        self.m_choice3.SetSelection(0)
        self.m_choice3.Hide()

        Settings.Add(self.m_choice3, wx.GBPosition(0, 3), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_staticText10 = wx.StaticText(self, wx.ID_ANY, u"PC端存放APK文件的路径：\n(路径中不能有中文)", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText10.Wrap(-1)
        self.m_staticText10.Hide()

        Settings.Add(self.m_staticText10, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_textCtrl4 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_textCtrl4.Hide()
        self.m_textCtrl4.SetMinSize(wx.Size(200, -1))

        Settings.Add(self.m_textCtrl4, wx.GBPosition(1, 1), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_staticText11 = wx.StaticText(self, wx.ID_ANY, u"将APK文件传输到设备上指定的路径：\n(不输入则默认为/sdcard/Download)", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText11.Wrap(-1)
        self.m_staticText11.Hide()

        Settings.Add(self.m_staticText11, wx.GBPosition(2, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_textCtrl5 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_textCtrl5.Hide()
        self.m_textCtrl5.SetMinSize(wx.Size(200, -1))

        Settings.Add(self.m_textCtrl5, wx.GBPosition(2, 1), wx.GBSpan(1, 1), wx.ALL, 5)

        gbSizer1.Add(Settings, wx.GBPosition(3, 0), wx.GBSpan(1, 1), wx.EXPAND, 5)

        Result = wx.GridBagSizer(0, 0)
        Result.SetFlexibleDirection(wx.BOTH)
        Result.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText12 = wx.StaticText(self, wx.ID_ANY, u"执行结果：", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText12.Wrap(-1)
        Result.Add(self.m_staticText12, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.m_textCtrl2 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE)
        self.m_textCtrl2.SetMinSize(wx.Size(400, 50))

        Result.Add(self.m_textCtrl2, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        gbSizer1.Add(Result, wx.GBPosition(4, 0), wx.GBSpan(1, 1), wx.EXPAND, 5)

        self.SetSizer(gbSizer1)
        self.Layout()
        gbSizer1.Fit(self)
        self.Centre(wx.BOTH)
        self.Bind(event=wx.EVT_BUTTON,handler=self.get_device,source=self.m_button3)
        self.Bind(event=wx.EVT_BUTTON, handler=self.conn_autobjs, source=self.m_button4)
        self.Bind(event=wx.EVT_BUTTON, handler=self.work, source=self.m_button2)
        self.Bind(wx.EVT_UPDATE_UI,self.show_controls)
    def __del__(self):
        pass




###########################################################################
## Class Error 提示弹窗界面
###########################################################################

class Info(wx.Dialog):

    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=u"提示", pos=wx.DefaultPosition, size=wx.Size(344,182),
                           style=wx.DEFAULT_DIALOG_STYLE)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        gbSizer6 = wx.GridBagSizer(0, 0)
        gbSizer6.SetFlexibleDirection(wx.BOTH)
        gbSizer6.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText4 = wx.StaticText(self, wx.ID_ANY, u"warning！", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText4.Wrap(-1)
        gbSizer6.Add(self.m_staticText4, wx.GBPosition(2, 0), wx.GBSpan(1, 1), wx.ALL, 5)

        self.SetSizer(gbSizer6)
        self.Layout()

        self.Centre(wx.BOTH)
        self.Bind(wx.EVT_UPDATE_UI, self.info_txt)




    def __del__(self):
        pass


###########################################################################
## Class Loading 加载界面
###########################################################################

class Loading(wx.Dialog):

    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
                           size=wx.Size(240, 80), style=0)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        gbSizer1 = wx.GridBagSizer(0, 0)
        gbSizer1.SetFlexibleDirection(wx.BOTH)
        gbSizer1.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText1 = wx.StaticText(self, wx.ID_ANY, u"请稍等...", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_staticText1.Wrap(-1)
        self.m_staticText1.SetMinSize(wx.Size(60, 20))

        gbSizer1.Add(self.m_staticText1, wx.GBPosition(1, 8), wx.GBSpan(1, 1), wx.ALL, 5)

        self.SetSizer(gbSizer1)
        self.Layout()
        self.Centre(wx.BOTH)
        self.Bind( wx.EVT_UPDATE_UI, self.wait_ui)

    def __del__(self):
        pass

